﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "AbilitySystem/ModMagCalc/MMC_MaxMana.h"

#include "AbilitySystem/StarrySkyAttributeSet.h"
#include "Interaction/CombatInterface.h"

UMMC_MaxMana::UMMC_MaxMana()
{
	//设置属性集中要补货的游戏属性,捕获活力属性
	IntelligenceDef.AttributeToCapture=UStarrySkyAttributeSet::GetVigorAttribute();
	//设置捕获的是源还是目标
	IntelligenceDef.AttributeSource=EGameplayEffectAttributeCaptureSource::Target;
	//不使用快照
	IntelligenceDef.bSnapshot=false;
	//定义属性配置的数组
	RelevantAttributesToCapture.Add(IntelligenceDef);
}

float UMMC_MaxMana::CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const
{
	//在游戏效果创建的时候捕获效果源上的所有标签
	const FGameplayTagContainer* SourceTags = Spec.CapturedSourceTags.GetAggregatedTags();
	//在游戏效果创建的时候捕获效果目标上的所有标签
	const FGameplayTagContainer* TargetTags = Spec.CapturedTargetTags.GetAggregatedTags();
	//从调用者/游戏代码传递的聚合器评估中使用的数据
	FAggregatorEvaluateParameters EvaluationParameters;
	//这个标签容器预计将保存游戏效果来源的所有聚合标签：来自能力系统组件、效果规格、能力、计算特定标签等。
	EvaluationParameters.SourceTags = SourceTags;
	//这个标签容器预计将保存游戏效果目标的所有聚合标签：来自效果规格、目标、计算特定标签等。
	EvaluationParameters.TargetTags = TargetTags;
	float Intelligence = 0.f;
	//调用方法捕获目标的活力属性赋值给Vigor
	GetCapturedAttributeMagnitude(IntelligenceDef,Spec,EvaluationParameters,Intelligence);
	//确保Vigor是正的不为负数
	Intelligence = FMath::Max(Intelligence,0.f);
	int32 PlayerLevel=1;
	//if(Spec.GetContext().GetSourceObject()->Implements<UCombatInterface>())
	//{
	//	PlayerLevel=CombatInterface->GetPlayerLevel();
	//}
	ICombatInterface* CombatInterface =Cast<ICombatInterface>(Spec.GetContext().GetSourceObject());
	check(CombatInterface);
	PlayerLevel=CombatInterface->GetPlayerLevel();
	return 50.f + 1.5f * Intelligence + 13.f * PlayerLevel;
}
